// 格式化计算机容量，网络流量等单位，size的单位默认为kb，
// 输入 1073741824
// 输出 1.00 TB
const calculateSize = function(size) {
    if (size == undefined) return '--';
    let bytes = typeof size == 'string' ? parseInt(size) : size;
    if (bytes === 0) return "0 KB";
    else {
        let k = 1024,
            unit = ["KB", "MB", "GB", "TB"],
            i = Math.floor(Math.log(bytes) / Math.log(k));
        let result = (bytes / Math.pow(k, i)).toFixed(2) + " " + unit[i];
        return result
    }
}
console.log(calculateSize(1024 * 1024 * 1024));